<template>
	<view class="wrap">
		<u-upload :ref="refName" :file-list="imgList" :action="action" :form-data="formData" @on-success="uploadSuccess" @on-remove="removeSuccess" :max-count="maxCount"></u-upload>
	</view>
</template>

<script>
	
	export default {
		props: {
			refName:{
				type:String,
				default:'uUpload'
			},
			imgList: {
				type: Array,
				default(){
					return [];
				}
			},
			maxCount:{
				type:[String,Number],
				default:9
			},
			action:{
				type:String,
				default:'https://up-z2.qbox.me'
			},
			formData:{
				type:Object,
				default(){
					return {};
				}
			}
		},
		data() {
			return {
				showUploadList: false,
				// 七牛云常用
				// qiniuData: {
				// 	token: ""
				// },
			}
		},
		mounted() {
			// this.lists = this.$refs.uUpload.lists;
			// this.lists = [
			// 	{url: 'https://xxxxx.png'}
			// ]
		},
		methods: {
			uploadSuccess(data, index, lists, name){
				this.changeImg(lists);
			},
			changeImg(lists){
				
				// 七牛云
				// let nLists = [];
				// for(let i=0;i<lists.length;i++){
				// 	if(lists[i].response){
				// 		nLists.push({
							
				// 			url:"https://pic.xxx.com/"+lists[i].response.hash
				// 		});
				// 	}else{
				// 		nLists.push({
				// 			url:lists[i].url
				// 		});
				// 	}
				// }
				this.$emit('changeImg',nLists);
			},
			removeSuccess(index, lists, name){
				this.changeImg(lists);
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>
